package org.bibpessoal.daos;

import java.sql.Connection;
import java.sql.SQLException;

import org.postgresql.ds.PGPoolingDataSource;

public class FabricaDeConexao {
	private static final String USUARIO = "postgres";
	private static final String SENHA = "postgres";
	private static final String BANCO = "bibliotecaDSW";
	
	private static PGPoolingDataSource pool = null;

	public static Connection getConexao() throws ClassNotFoundException, SQLException {
		inicializa();  
		return pool.getConnection();  
	}

	private static void inicializa() {
		if (pool == null) {
			pool = new PGPoolingDataSource();
			pool.setServerName("localhost");
			pool.setDatabaseName(BANCO);
			pool.setPortNumber(5432);
			pool.setUser(USUARIO);
			pool.setPassword(SENHA);
			pool.setMaxConnections(10);
		}
	}  
}